﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


namespace Data.Database
{
    public class Provincia
    {
        public int Id_Provincia { get; set; }
        public string NombreProvincia { get; set; }

        public static List<Provincia> GetAllProvincias()
        {
            string sql = @"SELECT * FROM Provincia ORDER BY NombreProvincia ASC";

            List<Provincia> list = new List<Provincia>();

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Turnet"].ToString()))
            {
                conn.Open();

                SqlCommand cmd = new SqlCommand(sql, conn);

                SqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    list.Add(LoadProvincia(reader));
                }

            }

            return list;
        }

        private static Provincia LoadProvincia(IDataReader reader)
        {
            Provincia item = new Provincia();

            item.Id_Provincia = Convert.ToInt32(reader["Id_Provincia"]);
            item.NombreProvincia = Convert.ToString(reader["NombreProvincia"]);

            return item;
        }

        

    }
}
